<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page language='java'
	import='java.util.*,javax.servlet.http.HttpServletRequest,com.shenfa.bean.Person'%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
Object obj=request.getSession().getAttribute("role_resource");
Person person = (Person) request.getSession().getAttribute("login");
if(null==obj){
	response.setStatus(1000);
	return;
}
%> 

		<script type="text/javascript">
		//账单类型下拉列表
		var type_store = new Ext.data.JsonStore( {
			fields: ["id", "text"],
			data: [{id: "1", text: "纸质"},{id: "2",text: "电子"}]
		});
		
		//模板状态下拉列表
	var state_store = new Ext.data.JsonStore({
		fields : [ "id", "text" ],
		data : [ {
			id : "0",
			text : "退回"
		}, {
			id : "1",
			text : "启用"
		}, {
			id : "2",
			text : "草稿"
		}, {
			id : "3",
			text : "审核中"
		} ]
	});
		
		var type_store1 = new Ext.data.JsonStore({
		fields : [ "id", "text" ],
		data : [ {
			id : "",
			text : "全部"
		},{
			id : "1",
			text : "纸质"
		}, {
			id : "2",
			text : "电子"
		} ]
	});
		//卡产品树数据源
		var tree_store = new Ext.data.JsonStore({
    		root: "data",
    		fields: ["id","text","leaf"],
    		url: "product!ProdType.action"
    	});
		//模板列表数据源
		var data_store = new Ext.data.JsonStore({
    		root: "data",
    		totalProperty: "total",
    		fields: ["id", "name","version", "cardid", "cardname", "type", "storpath", "jobpath", "images", "state", "personid","createtime","images"],
  			url: "template!VerifyList.action"
    	});
    	//模板从表数据源
		var sub_store = new Ext.data.JsonStore({
    		root: "data",
    		totalProperty: "total",
    		fields: ["stencil_no", "version","in_no", "in_name"],
  			url: "template!listTemplateSub.action"
    	});
    	//图片路径,上传
    	var image_store = new Ext.data.JsonStore({
    		root: "data",
    		fields: ["path"],
  			url: "template!queryImage.action"
    	});
    	//个性化区域
		var area_store = new Ext.data.JsonStore( {
			root: "data",
			totalProperty: "total",
			fields: ["id","name", "type","tempno","version","remark"],
			url: "templatearea!list.action"
		});
		var araetype_store = new Ext.data.JsonStore( {
		fields: ["id", "text"],
		data: [{id: "1",text: "图片"},{id: "2",text: "文本"},{id: "3",text: "列表"},{id: "4",text: "自动填充"}]
		});
 			
			//定义数据显示面板
			var p1 = {
				id: "p1",
				xtype: "grid",
				stripeRows: true,
				loadMask: true,//在加载数据时遮罩住元素,替换元素Updater的加载提示器，并且在初始化加载之后销毁
				autoExpandColumn: "storpath",//自动填充
				autoExpandMin: 100,//自动填充最小宽度
				headersDisabled: true,
				store: data_store,
				columns: [
	    	    	new Ext.grid.RowNumberer({header: "序号", width: 35}),
	        		{header: "模板编号", dataIndex: "id",menuDisabled: true},
	        		{header: "名称", dataIndex: "name",menuDisabled: true},
	        		{header: "版本", dataIndex: "version",menuDisabled: true},
					{header: "卡产品", dataIndex: "cardname",menuDisabled: true},
					{header: "类型", dataIndex: "type",menuDisabled: true,
					renderer: function(input){
						if("1"==input)return "纸质";
						else if("2"==input)return "电子";
					}},
					{header: "存储路径", dataIndex: "storpath", id: "storpath",menuDisabled: true},
					{header: "状态", dataIndex: "state",menuDisabled: true,
					renderer: function(input){
						if("0"==input)return "退回";
						else if("1"==input)	return "启用";
						else if("2"==input)	return "草稿";
						else if("3"==input)	return "审核中";
					}},
					{header: "创建人", dataIndex: "personid",menuDisabled: true},
					{header: "创建时间", dataIndex: "createtime",menuDisabled: true}
				],
				buttonAlign: "center",
				bbar: new Ext.ux.PagingToolbar({
          	 	 	pageSize: limit,
         	   		store: data_store
        		}),
				buttons: [{
					text: "查看详情", 
					handler: function(){
						var p1 = this.ownerCt.ownerCt;
						var panel = p1.ownerCt;
						var record = p1.getSelectionModel().getSelected();
						if (record){
							Ext.getCmp("p2").setParam(record.data);
							oper_type = "upd";
							sub_store.load({params: {"templateSub.stencil_no": record.data.id}});
							image_store.load({params: {"template.id": record.data.id}});
							area_store.load({params: {"temparea.tempno": record.data.id}});
							panel.layout.setActiveItem(1);
						}else{
							Ext.Msg.alert("错误","未选中任何行信息,无法进行此操作!");
						}			
					}
				}],
				//查询条件
				tbar: ["&nbsp&nbsp账单类型：",
					  {
					xtype : "billCombox",
					width : 120,
					store : type_store1,
					id : "selcbut",
					value: "",
					listeners : {
						"select" : function(comb, rcord, index) {
							var node = Ext.getCmp("tempTree").getSelectionModel().getSelectedNode();
							if (node) {
								if (node.isLeaf()) {
									data_store.baseParams["template.type"] = rcord.data.id;
									data_store.load({
										params : {
											start : 0,
											limit : limit
										}
									});
								}
							} else {
								//Ext.Msg.alert("提示", "未选中任何行卡产品信息,无法执行此操作!");
								Ext.Msg.show({
		   							title:"警告",
		   							msg: "未选中任何行信息,无法进行此操作!",
		   							buttons: Ext.Msg.OK,
		   							animEl: "elId",
		   							icon:Ext.MessageBox.WARNING
							});
							}
						}
					}
				},"&nbsp&nbsp模板名称：",
					  {
						xtype : "textfield",
						id : "selcsnamebut",
						enableKeyEvents:true,
						listeners : {
							"keypress" : function(t,e) {
								if(13==e.getKey()){
								var node = Ext.getCmp("tempTree").getSelectionModel().getSelectedNode();
								if (node) {
									if (node.isLeaf()) {
										data_store.baseParams["template.name"] = t.getValue();
										data_store.load({
											params : {
												start : 0,
												limit : limit
											}
										});
									}
								} else {
									//Ext.Msg.alert("提示", "未选中任何行卡产品信息,无法执行此操作!");
									Ext.Msg.show({
			   							title:"警告",
			   							msg: "未选中任何行信息,无法进行此操作!",
			   							buttons: Ext.Msg.OK,
			   							animEl: "elId",
			   							icon:Ext.MessageBox.WARNING
								});
								}
								}
							}
						}
				}  ]
			};


		//详细信息
			var p2 = {
				id: "p2",
			    labelWidth: 125,
				xtype: "form",
				region: "north",
				height: 225,
			    bodyStyle: "padding: 5px 5px 0",
				defaultType: "textfield",
				items: [{
					id: "template.id", 
					fieldLabel: "模板编号",	
					name: "template.id",
					anchor: "100%",
					disabled: true
				},{
					id: "template.name", 
					fieldLabel: "模板名称",	
					vtype: "alphanumchinese",
					name: "template.name",
					anchor: "100%",
					disabled: true
				},{
					id: "template.version", 	  
					fieldLabel: "版本号",				
					name: "template.version",
					anchor: "100%",
					disabled: true
				},{
					id: "template.cardid", 	  
					hidden: true, 					
					name: "template.cardid"
				},{
					id: "template.cardname", 
					fieldLabel: "卡产品名称",  
					name: "template.cardname",
					anchor: "100%",
					disabled: true
				},{
					id: "template.state",
					fieldLabel: "状态",
					name: "template.state",
					xtype: "billCombox",
					store: state_store,
					anchor: "100%",
					disabled: true
				},{
					id: "template.type",
					fieldLabel: "账单类型",
					name: "template.type",
					xtype: "billCombox",
					store: type_store,
					disabled: true
				},{
					id: "template.storpath",
					fieldLabel: "模板存储路径",
					name: "template.storpath",
					anchor: "100%",
					disabled: true
				},{
					id: "template.jobpath",
					fieldLabel: "JOB文件存储路径",
					name: "template.jobpath",
					anchor: "100%",
					disabled: true
				}],
				setParam: function(data){
					var p2 = this;
					p2.getComponent("template.id").setValue(data.id);
					p2.getComponent("template.name").setValue(data.name);
					p2.getComponent("template.version").setValue(data.version);
					p2.getComponent("template.cardid").setValue(data.cardid);
					p2.getComponent("template.cardname").setValue(data.cardname);
					p2.getComponent("template.type").setValue(data.type);
					p2.getComponent("template.storpath").setValue(data.storpath);
					p2.getComponent("template.jobpath").setValue(data.jobpath);
					p2.getComponent("template.state").setValue(data.state); 
					//用户自身提交审核中状态都不允许启用，退回
					if(data.personid == "<%=person.getId()%>" || data.state == 0 || data.state == 2) {
						Ext.getCmp("qy").setDisabled(true);
						Ext.getCmp("th").setDisabled(true);
					} else if(data.state == 1){	//启用状态只允许退回
						Ext.getCmp("qy").setDisabled(true);
						Ext.getCmp("th").setDisabled(false);
					}else {	//其他用户提交审核中，可启用，退回
						Ext.getCmp("qy").setDisabled(false);
						Ext.getCmp("th").setDisabled(false);
					}
				}
				};


				//区域基本信息
		var p3 = {
				xtype: "grid",
				region: "south",
				columnWidth: 1,
				title: "个性化区域信息",
				autoExpandColumn: "area_remark",//自动填充
				autoExpandMin: 100,//自动填充最小宽度
				height: 110,
				headersDisabled: true,
				region: "south",
				store: area_store,
				columns: [new Ext.grid.RowNumberer( 
							{header: "序号",width: 35}),
							{dataIndex: "id",header: "区域编号",menuDisabled: true},
				            {dataIndex: "name",header: "区域名称",menuDisabled: true},
				            {dataIndex: "type",header: "区域类型",menuDisabled: true,
						          renderer: function(input){
						             if(input){
							             if(""==input)return input;
				            			 var res2=araetype_store.getById(input);
										 return res2.data.text;
									 }
			            		  }
				            },
				            {dataIndex: "remark",header: "备注",id: "area_remark",menuDisabled: true}
			         ]
				};
	

			var p4 = {
				xtype: "grid",
				title: "输入区域信息",
				region: "center",
				autoExpandColumn: "in_name",//自动填充
				autoExpandMin: 100,//自动填充最小宽度
				store: sub_store,
				headersDisabled: true,
				columns: [ new Ext.grid.RowNumberer({
					header: "序号",
					width: 35
				}), {
					dataIndex: "in_no",
					id: "in_no",
					header: "输入编号",
					menuDisabled: true
				}, {
					dataIndex: "in_name",
					id: "in_name",
					header: "输入名称",
					menuDisabled: true
				} ]
			};

			//上传个性化区域
			var p5 = {
				xtype: "grid",
				region: "west",
				width: 300,
				enableColumnMove: false,
				enableHdMenu: false,
				title: "样张提示图",
				loadMask: true,
				headersDisabled: true,
				autoExpandColumn: "path",
				autoExpandMin: 100,				
				selModel: new Ext.grid.RowSelectionModel(),//设置为行选择器
				store: image_store,
				columns: [
						new Ext.grid.RowNumberer({
							header: "序号",
							width: 35
						}),
						{
							dataIndex: "path",
							header: "文件名称",
							id: "path",
							menuDisabled: true
						},{
							xtype: "actioncolumn",
							header: "预览",
			                width: 34,
			                menuDisabled: true,
    						items: [{
			                    icon: "images/shared/icons/fam/information.png",  // Use a URL in the icon config
			                    tooltip: "预览",
			                    handler: function(grid, rowIndex, colIndex) {
									var rec = image_store.getAt(rowIndex);
									var win=Ext.getCmp("showimages");
									win.show();
									var html="<img id='imgpage' src='download.action?id="+encodeURI(rec.get('path'))+"' width="+win.getInnerWidth()+" height="+win.getInnerHeight()+" />";
									win.update(html);									
			                    }
			                }]
						}     				 
    			]
			};
			
			//详细信息
			var p6 = {
				id: "p6",
			    labelWidth: 125,
			    autowidth: true,
				autoScroll: true,
				boxMinHeight: 500,
				layout: "border",
				border: false,
				items: [p2,p5,p4,p3],
				buttonAlign: "center",
				buttons: [{id: "qy", text: "启用", handler: function(){
					var id = Ext.getCmp("template.id").getValue();
					var name = Ext.getCmp("template.name").getValue();
					var version = Ext.getCmp("template.version").getValue();
					var cardid = Ext.getCmp("template.cardid").getValue();
					var type = Ext.getCmp("template.type").getValue();
					var storpath = Ext.getCmp("template.storpath").getValue();
					var jobpath = Ext.getCmp("template.jobpath").getValue();
					var state = Ext.getCmp("template.state").getValue();

					var url="template!updState.action";
					
					var params = {"template.id": id,
							"template.name": name,
							"template.version": version,
							"template.cardid": cardid,
							"template.type": type,
							"template.state": 1
						};	
					
					var params2 = {
						"template.cardid": cardid
					};
					oper(url,params,params2,Ext.getCmp("templ_panel"));
				}},{id: "th", text: "退回", handler: function(){
					var id = Ext.getCmp("template.id").getValue();
					var name = Ext.getCmp("template.name").getValue();
					var version = Ext.getCmp("template.version").getValue();
					var cardid = Ext.getCmp("template.cardid").getValue();
					var type = Ext.getCmp("template.type").getValue();
					var storpath = Ext.getCmp("template.storpath").getValue();
					var jobpath = Ext.getCmp("template.jobpath").getValue();
					var state = Ext.getCmp("template.state").getValue();

					var url="template!updState.action";
					
					var params = {"template.id": id,
							"template.name": name,
							"template.version": version,
							"template.cardid": cardid,
							"template.type": type,
							"template.state": 0
						};	
					
					var params2 = {
						"template.cardid": cardid
					};
					oper(url,params,params2,Ext.getCmp("templ_panel"));
				}},{text: "取消", handler: function(){
					Ext.getCmp("templ_panel").layout.setActiveItem(0);
				}
			}]
		};

		var temps_pel = new Ext.Panel({
			id: "panel",
			border: false, 	
			layout: "border",
			items: [{
				id: "tempTree",
				xtype: "billTreePanel",
				dataUrl: "tree!product.action",
				autoScroll: true,
				root: new Ext.tree.AsyncTreeNode({
					id: "root",
					expanded: true
				}),
				listeners: {
					"click": function(node){
						tree_store.load({params: {node: node.attributes.id}});
						if(node.isLeaf()) {
							Ext.getCmp("selcbut").setValue("");//清空查询条件
							Ext.getCmp("selcsnamebut").setValue("");//清空查询条件
							
							data_store.baseParams ={};
							data_store.baseParams["template.cardid"] = node.id;
							data_store.load({params: {start: 0,limit: limit}});
							Ext.getCmp("templ_panel").layout.setActiveItem(0);
						}
					}
				}},{
					id: "templ_panel",
					region: "center",
					border: false, 
					layout: "card",
					activeItem: 0,//显示第一个容器
					items: [p1, p6]
				}]
		});	
		
		var oper = function(url, params, parent, panel){
			Ext.Ajax.request({
				clientValidation: true,
				params: params,
				url: url,
				success: function(response, opts){
					var d=eval("("+response.responseText+")");
					if(d.code == "1"){
						if(parent != null) {
							Ext.getCmp("p1").getBottomToolbar().doRefresh();
							//data_store.load({params: parent});
						}
						Ext.Msg.alert("成功",d.data);
						if(panel != null){
							panel.layout.setActiveItem(0);
						}
					} else {
						Ext.Msg.alert("失败",d.data);
					}
				},
				failure: function(response, opts){
				}
			});
		};
		
	var CenterPanel=Ext.getCmp("CenterPanel");
	CenterPanel.removeAll();
	CenterPanel.add(temps_pel);
	CenterPanel.doLayout();
	</script>